<?php
include("./config.php");
include("./utils.php");
checkLogin();
?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>新加</title>
  <?php include 'scripts-inc.php' ?>

  <script>
  var userid="<?php echo $_COOKIE['userid']; ?>";
  $(function(){
    $("#insert_category").val("<?php if(isset($_GET["cate"])) echo $_GET["cate"]; else echo 0; ?>");
    $("#tmode").val("<?php if(isset($_GET["mode"])) echo $_GET["mode"]; else echo 0; ?>");
    $("#tappe").val("0");
    $("#insert").click(function(){
      var data = {
        userid:userid,
        name:$("#insert_name").val(),
        url:$("#insert_url").val(),
        desc:$("#insert_desc").val(),
        category:$("#insert_category").val(),
        appe:$("#tappe").val(),
        mode:$("#tmode").val()
      };
      show_msg("#content", "提交中...");
      $.post("insert-data.php", data, function(msg){
        show_msg("添加成功：ID=" + msg);
        //window.history.back();
        window.location.href=document.referrer; 
        show_msg("#content", "添加完成");
      })
    });

    $("#smart").click(function(){
      var data = {
        url:$("#insert_url").val(),
      };

      $("#content").text("提交中...");
      $.post("smart-url.php", data, function(msg){
        var d = {};
        eval("d="+msg);
        if (d["name"]) {
          $("#insert_name").val(d["name"]);
          $("#insert_desc").val(d["name"]);
        }
        $("#content").text("操作完成");
      });
    });
  });//end of $(function(){

  </script>
</head>
<body>
<!-- template -->
<!-- end of template -->


<div id="wrapper">
<div id="container">
<!-- .................................................... -->

<div id="nav_data_src">
    <?php include 'navbars-inc.php' ?>
</div>

<div id="insert_container" class="">
<div>
  <div class="form-group row">
      <label for="insert_name" class="col-sm-1 control-label">标题</label>
      <div class="col-sm-5">
        <input type="" class="form-control" id="insert_name" name="insert_name" placeholder="标题">
      </div>
  </div>
  <div class="form-group row">
    <label for="insert_url" class="col-sm-1 control-label">网址</label>
    <div class="col-sm-5">
      <input type="" class="form-control" id="insert_url" name="insert_url" placeholder="URL网址">
    </div>
    <div class="">
        <button type="submit" class="btn btn-primary" id="smart">自动</button>
    </div>
  </div>

  <div class="form-group row">
    <label for="insert_category" class="col-sm-1 control-label">类别</label>
    <div class="col-sm-5">
      <input type="" class="form-control" id="insert_category" name="insert_category" placeholder="类别">
    </div>
  </div>
  <div class="form-group row">
    <label for="tappe" class="col-sm-1 control-label">外观</label>
    <div class="col-sm-5">
      <input type="" class="form-control" id="tappe" name="tappe" placeholder="外观1-4">
    </div>
  </div>
  <div class="form-group row">
    <label for="tmode" class="col-sm-1 control-label">模式</label>
    <div class="col-sm-5">
      <input type="" class="form-control" id="tmode" name="tmode" placeholder="模式0-1">
    </div>
  </div>
  <div class="form-group row">
    <label for="insert_desc" class="col-sm-1 control-label">说明</label>
    <div class="col-sm-5">
      <textarea class="form-control" id="insert_desc" rows="5" name="insert_desc" placeholder="对这个网址的介绍"></textarea>
    </div>
  </div>
  <div class="col-sm-5 text-center">
    <a href="./show-app.php" type="button" class="btn btn-primary">取消</a>
    <button type="submit" class="btn btn-primary" id="insert">提交</button>
  </div>
</div>


</div> <!-- end of insert_container -->

<div id="content">
</div><!-- end of content -->

<!-- .................................................... -->
</div><!-- end of container -->
</div><!-- end of wrapper -->
</body>
</html>
